package pub.guoxin.oops.manager.handler;

import pub.guoxin.oops.enums.ComparisonOperator;
import pub.guoxin.oops.model.DataAlarmConfig;

/**
 * 两个边界值
 * <p>
 * Create by guoxin on 2018/3/30
 */
public abstract class AbstractTwoBoundaryAlarmInfoHandler extends AbstractAlarmInfoHandler {

    protected ComparisonOperator judgmentBoundaryValue(Float value, String fieldName) {
        DataAlarmConfig deviceBattery = dataAlarmConfigRepository.findByFieldName(fieldName);
        Double min = (Double) deviceBattery.getBoundary().getMin();
        Double max = (Double) deviceBattery.getBoundary().getMax();
        if (value <= min)
            return ComparisonOperator.LESS_THAN;
        if (value >= max)
            return ComparisonOperator.GREATER_THAN;
        return null;
    }
}
